import torch
from CVAE import CVAE,test_loader, loss_function,embedding_dim

# 加载模型
model = CVAE(input_dim=embedding_dim, latent_dim=32)
model.load_state_dict(torch.load('src/model_pth/cvae_model.pth',weights_only=True))
model.eval()

# 测试模型
test_loss = 0
with torch.no_grad():
    for image_emb, text_emb in test_loader:
        recon_batch, mu, logvar = model(image_emb, text_emb)
        test_loss += loss_function(recon_batch, text_emb, mu, logvar).item()

test_loss /= len(test_loader.dataset)
print(f'Test Loss: {test_loss:.4f}')
